<template>
  <el-dialog :close-on-click-modal="false"   title="指派" :visible="show" :before-close="close">
    <el-form ref="form" :model="form" :rules="rules" label-width="100px">
      <el-form-item label="处理部门" prop="deptCode">
        <SelectGroup3 v-model="form.deptCode" @change="(e) => (form.deptName = e.name)"></SelectGroup3>
      </el-form-item>
      <el-form-item label="备注" prop="remark">
        <el-input v-model="form.remark" type="textarea" :autosize="{ minRows: 4, maxRows: 6 }" placeholder="请输入"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="close">取 消</el-button>
      <el-button type="primary" @click="submit">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import SelectGroup3 from './selectGroup3.vue'
import { eventTransfer } from '@/api/event';

export default {
  components: {SelectGroup3},
  props: {
    /* 显示隐藏 */
    show: {
      type: Boolean,
      default: false
    },
    item: {
      type: Object,
      default: {}
    }
  },
  watch: {
    item: {
      handler(val) {
        this.form = val || {};
      },
      immediate: true
    },
    show: {
      handler(val) {
        val && this.resetForm('form');
      },
      immediate: true
    }
  },
  data() {
    return {
      form: {},
      rules: {
        deptCode: [{ required: true, message: '请输入内容', trigger: ['change', 'input'] }]
      }
    };
  },
  methods: {
    submit() {
      console.log('打印当前编辑：', this.form);
      this.$refs['form'].validate((valid) => {
        if (valid) {
          eventTransfer(this.form).then((res) => {
            // 验证成功-编辑
            this.$emit('change', this.form);
            this.close();
          });
        }
      });
    },
    close() {
      this.form = {};
      this.$emit('update:show', false);
    }
  }
};
</script>

<style lang="scss" scoped>
.app-container {
}
</style>
